﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using TS3QueryLib.Core.CommandHandling;

namespace TS3QueryLib.Tests.CommandHandling
{
    [TestClass]
    public class CommandTest
    {
        [TestMethod]
        public void TestCommandNameOnly()
        {
            Assert.AreEqual("unknowncommand", new Command("UnknownCommand").ToString());
            Assert.AreEqual("use", new Command(CommandName.Use).ToString());
        }

        [TestMethod]
        public void TestCommandNameAndOptions()
        {
            Assert.AreEqual("unknowncommand -luck", new Command("UnknownCommand", "luck").ToString());
            Assert.AreEqual("unknowncommand -luck -skill", new Command("UnknownCommand", "luck", "skill").ToString());
            Assert.AreEqual("use -luck", new Command(CommandName.Use, "luck").ToString());
            Assert.AreEqual("use -luck -skill", new Command(CommandName.Use, "luck", "skill").ToString());
        }

        [TestMethod]
        public void TestAllWithSingleGroup()
        {
            Command command;

            command = new Command(CommandName.Use, "luck");
            command.AddParameter("lucker");
            Assert.AreEqual("use lucker -luck", command.ToString());

            command = new Command(CommandName.Use, "luck", "skill");
            command.AddParameter("lucker");
            Assert.AreEqual("use lucker -luck -skill", command.ToString());

            command = new Command(CommandName.Use, "luck", "skill");
            command.AddParameter("lu|cker");
            Assert.AreEqual(@"use lu\pcker -luck -skill", command.ToString());

            command = new Command(CommandName.Use, "luck", "skill");
            command.AddParameter("lu|cker");
            command.AddParameter("sk|ller");
            Assert.AreEqual(@"use lu\pcker sk\pller -luck -skill", command.ToString());

            command = new Command(CommandName.Use, "luck");
            command.AddParameter("lucklevel", 5);
            Assert.AreEqual("use lucklevel=5 -luck", command.ToString());

            command = new Command(CommandName.Use, "luck", "skill");
            command.AddParameter("lucklevel", 5);
            Assert.AreEqual("use lucklevel=5 -luck -skill", command.ToString());

            command = new Command(CommandName.Use, "luck", "skill");
            command.AddParameter("lucklevel", 5);
            command.AddParameter("skilllevel", 10);
            Assert.AreEqual("use lucklevel=5 skilllevel=10 -luck -skill", command.ToString());
        }

        [TestMethod]
        public void TestAllWithMultipleGroups()
        {
            Command command = new Command(CommandName.ServerGroupAddPerm);
            command.AddParameter("sgid", 13);
            command.AddParameter("permid", 17276);
            command.AddParameter("permvalue", 50);
            command.AddParameter("permnegated", 0);
            command.AddParameter("permskip", 0);

            command.AddParameter("permid", 21415, 1);
            command.AddParameter("permvalue", 20, 1);
            command.AddParameter("permnegated", 0, 1);

            Assert.AreEqual("servergroupaddperm sgid=13 permid=17276 permvalue=50 permnegated=0 permskip=0|permid=21415 permvalue=20 permnegated=0", command.ToString());
        }
    }
}